<!--
 * @Description: 课程订单- 图书订单
 * @Author: your name
 * @Date: 2024-05-09
 * @LastEditTime: 2024-05-09
 * @LastEditors: Please set LastEditors
-->

<template>
  <div class="confirmPayment">
    <div class="order_bg">
      <div class="heart_w">
        <div class="order_left">
          <!-- <img src="@/assets/images/graybook.png" alt="" /> -->
          确认订单
        </div>
        <div class="order_right">
          <ul>
            <li>
              <img src="@/assets/images/order_white.png" alt="" />
              <p class="pactive">订单填写</p>
            </li>
            <li>
              <img src="@/assets/images/line.png" alt="" />
            </li>
            <li>
              <img src="@/assets/images/online_pay.png" alt="" />
              <p>在线支付</p>
            </li>
            <li>
              <img src="@/assets/images/line.png" alt="" />
            </li>
            <li>
              <img src="@/assets/images/order_comp.png" alt="" />
              <p>订单完成</p>
            </li>
          </ul>
        </div>
      </div>
    </div>

    <!-- 商品信息 -->
    <div class="busine_info heart_w">
      <!-- 收货地址 -->
      <div class="shipping_address" v-if="type == 2">
        <h3>选择收货地址</h3>
        <div style="margin-bottom: 10px">
          <ul>
            <li
              class="list_item"
              v-for="(item, index) in addressList"
              :key="item.id"
            >
              <div
                class="item_status"
                :class="
                  active_it == index + 1
                    ? 'active'
                    : item.is_default == 1
                    ? 'active'
                    : ''
                "
                @click="setDefaultAddress(item, index)"
              >
                <p></p>
                <!-- <p>设为默认地址</p> -->
              </div>
              <p>
                {{ item.name }} &nbsp;&nbsp;&nbsp;{{
                  item.province.name
                }}&nbsp;&nbsp; {{ item.city.name }}&nbsp;&nbsp;
                {{ item.area.name }} {{ item.mobile }}
              </p>
            </li>
          </ul>
        </div>
        <el-button type="danger" size="small" @click="openAddress">
          添加新地址
        </el-button>
      </div>

      <div>
        <h1>商品信息</h1>
        <div class="book">
          <img :src="boxListObj.image" class="bookimg" />
          <h2>{{ boxListObj.title }}<small>x1</small></h2>
          <p>
            ¥<span class="bigmoney">{{ boxListObj.price }}</span>
          </p>
        </div>
      </div>

      <!-- 协议 -->
      <div
        id="appAgreement"
        style="
          padding: 0px 30px 0px 39px;
          height: 40px;
          line-height: 40px;
          font-size: 16px;
        "
      >
        <el-checkbox
          v-model="checked"
          @change="getSencond(checked)"
          style="color: #bd0000"
        >
          购买前请阅读融跃教育《用户购买须知》
        </el-checkbox>
        <el-dialog
          :visible.sync="Successdialog"
          width="75%"
          :before-close="sendMsg"
          :show-close="false"
          center
        >
          <span
            style="font-size: 18px; font-weight: 600"
            :class="Sencond !== 0 ? 'span_active' : 'active'"
          >
            阅读 {{ Sencond }} 秒后可关闭页面
          </span>
          <div class="dialog_wrap">
            <div class="dialog_title">《用户购买须知》</div>
            <div class="dialog_content">
              <iframe
                src="https://img.rongyuejiaoyu.com//uploads/20240316/271ebe2fe6dcd98b45d760c14d9837d3.pdf?page=hsn#toolbar=0"
                toolbar="0"
                frameborder="0"
                style="width: 75vw; height: 70vh"
              >
              </iframe>
            </div>
          </div>
          <!-- 底部按钮 -->
          <span slot="footer" class="dialog-footer">
            <el-button
              @click="confirm"
              type="danger"
              :disabled="isDisabled"
              v-if="Sencond === 0"
            >
              我已全部阅读并同意
            </el-button>
          </span>
        </el-dialog>
      </div>

      <ul class="rightinfo">
        <li v-for="(item, index) in priceArr" :key="index">
          {{ item.title }}：<span>
            <i class="zhekouMoney" style="font-style: normal; color: #fe6444">
              ￥ {{ item.price }}
            </i>
          </span>
        </li>
        <li>
          共1件商品，商品总金额：<span>
            <i class="orMoney" style="font-style: normal; color: #fe6444">
              ￥ {{ numSum }}
            </i>
          </span>
        </li>
        <!-- <li>
          应付：<span class="impormoney">
            <i class="jine">￥25980.00</i>
          </span>
        </li> -->
        <!-- <li>购买账号：<span>13203952910</span></li> -->
        <li style="display: flex; align-items: center; justify-content: end">
          <button class="submitorder" @click="placeOrder">提交订单</button>
        </li>
      </ul>
    </div>

    <!-- 地址新增 -->
    <DialogCombo ref="dialog"></DialogCombo>
  </div>
</template>

<script>
import { getPayment } from '@/api/payment.js'
import DialogCombo from '@/components/common/DialogCombo.vue'
import { getAddressAll } from '@/api/address'

export default {
  name: 'confirm_order_combo',
  components: {
    DialogCombo
  },
  data() {
    return {
      payId: '',
      type: '',
      active_it: 1,
      radioAddress: 1,
      addressList: [],
      boxListObj: {},
      checkedBook: true,
      priceArr: [],
      Sencond: 10,
      coupon_id: 0, // 优惠卷
      numSum: '',
      isDisabled: false,
      checked: false,
      Successdialog: false //控制弹出
    }
  },
  created() {
    this.payId = this.$route.query.id
    this.type = this.$route.query.type
    console.log(this.$route.query)
    this.payOrderData()
    this.getAddressList()
  },
  methods: {
    async payOrderData() {
      let { data: data } = await getPayment({ id: this.payId })
      this.boxListObj = data.data.box
      this.priceArr = data.data.price
      // 总价* 数量 toFixed(2)
      this.numSum = data.data.box.price
    },
    setDefaultAddress(it, i) {
      console.log(it, i)
      this.active_it = i + 1
    },
    placeOrder() {
      if (this.checked) {
        this.$router.push({
          path: '/pay_combo',
          query: { id: this.boxListObj.id, coupon_id: this.coupon_id }
        })
      } else {
        this.$message.warning({
          message: '请勾选协议!',
          type: 'warning',
          iconClass: ' ', // 这个会覆盖图标类名，为了实现去掉图标的操作
          customClass: 'el-message--warning' // 这个是由于上面设置了iconClass会覆盖掉type，所以需要再设置
        })
      }
    },
    getSencond(val) {
      if (val) {
        this.Successdialog = true
        this.Sencond = 8
        const that = this
        const interval = setInterval(function () {
          --that.Sencond
          if (that.Sencond === 0) {
            that.isDisabled = false
            that.checked = false
            clearInterval(interval)
          }
        }, 1000)
      } else {
        this.checked = false
      }
    },
    getAddressList() {
      getAddressAll().then(({ data: data }) => {
        this.addressList = data.data
      })
    },
    openAddress() {
      this.$refs.dialog.open()
    },
    confirm() {
      if (this.Sencond === 0) {
        this.Successdialog = false
        this.checked = true
      }
    },
    sendMsg() {
      if (this.Sencond === 0) {
        this.Successdialog = false
        this.checked = false
        console.log(213)
        console.log(this.checked)
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/styles/order_combo.scss';

.confirmPayment {
  padding-bottom: 35px;
}

#appAgreement {
  ::v-deep {
    .el-checkbox__inner {
      border-color: #bd0000;
    }

    .el-checkbox__input.is-checked .el-checkbox__inner {
      border-color: #409eff !important;
    }
  }
}

.busine_info {
  h2 {
    small {
      padding-left: 48px;
    }
  }
  .book {
    width: 1113px;
    height: 162px;
    background: #f3f5f7;
    margin: 20px auto 39px;
    position: relative;
    img {
      width: 158px;
      height: 113px;
      margin: 26px 0 0 28px;
      float: left;
      border-radius: 5px;
    }
    h2 {
      font-size: 16px;
      color: #333;
      position: absolute;
      left: 210px;
      top: 50px;
    }
    p {
      font-size: 20px;
      position: absolute;
      left: 210px;
      top: 100px;
      color: #fe6444;
    }
  }

  /* 选择地址 */
  .shipping_address {
    width: 1112px;
    margin: 0 auto;

    h3 {
      line-height: 64px;
      font-size: 18px;
      font-weight: normal;
      color: #666;
    }

    ul {
      border-bottom: 1px solid #e5e5e5;
      padding-bottom: 8px;
    }
    .list_item {
      display: flex;
      align-items: center;
      line-height: 38px;
      position: relative;

      .active {
        p:first-child {
          border: 1px solid #2280f0 !important;
          &::after {
            content: ' ';
            display: block;
            background: #2280f0;
            width: 10px;
            height: 10px;
            text-align: center;
            margin: 3px auto;
            border-radius: 50%;
          }
        }
      }

      .item_status {
        display: inline-block;
        position: relative;
        cursor: pointer;
        font-weight: 500;
        color: #606266;
        margin-right: 6px;

        p:first-child {
          content: ' ';
          display: block;
          border-radius: 50%;
          width: 16px;
          height: 16px;
          border: 1px solid #ccc;
          position: absolute;
          top: -8px;
          left: -25px;
        }
      }

      ::v-deep {
        .el-radio {
          margin-right: 0;
        }
      }
      p {
        margin-left: 23px;

        &:hover {
          background: #fff3f3;
        }
      }
    }
  }
}

.rightinfo {
  text-align: right;
  margin-right: 45px;
  font-size: 18px;

  li {
    height: 40px;
    line-height: 40px;
    color: #999;

    .jine {
      color: #e8433a;
      font-size: 22px;
      font-weight: bold;
      font-style: normal;
    }

    button {
      width: 120px;
      height: 40px;
      background: linear-gradient(-90deg, #fa4e4e, #fd894f);
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 15px;
      color: #fff;
      border: none;
      cursor: pointer;
    }
  }
}

/* 页签样式 */

.dialog_wrap {
  background-color: #fff;
  box-sizing: border-box;
}

.dialog_title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 25px;
}

.dialog_content {
  overflow-y: auto;
  line-height: 1.5;
}

.span_text {
  cursor: pointer;
  margin: 10px 10px;
  border-radius: 5px;
  display: inline-block;
  width: 80px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  border: 1px solid skyblue;
}

.span_active {
  color: #ccc;
}
</style>
